package com.zzyq.pc.web.user.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zzyq.pc.utils.JsonUtils;
import com.zzyq.pc.web.configure.model.Company;
import com.zzyq.pc.web.configure.model.Depart;

/**
 * 用户实体
 * 
 * @author sywd
 *
 */
public class User implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 206946955079470679L;
    /**
     * 用户数据自增ID
     */
    private Integer userId;
    /**
     * 用户账号-可用于登录
     */
    private String userAccount;
    /**
     * 用户名称-用于显示
     */
    private String userName;
    /**
     * 登录密码
     */
    @JsonIgnore
    private String userPwd;

    /**
     * 加密盐值
     */
    @JsonIgnore
    private String userSalt;
    /**
     * 手机号 - 可用于登录
     */
    private String userPhone;
    /**
     * 职务
     */
    private String userJob;
    /**
     * 是否删除,0-未删除
     */
    @JsonIgnore
    private Integer isDelete;
    /**
     * 用户类型
     */
    @JsonIgnore
    private Integer userType;
    /**
     * 设置单设备登录
     */
    @JsonIgnore
    private Integer singleLogin;
    /**
     * 角色所属系统
     */
    @JsonIgnore
    private Integer userSys;
    /**
     * 部门信息
     */
    private Depart depart;
    /**
     * 团体信息
     */
    private Company company;
    /**
     * 最高级别角色
     */
    private Role maxRole;
    /**
     * 权限列表
     */
    private List<String> perms;
    @JsonIgnore
    private List<Role> roles;
    @JsonIgnore
    private List<Permission> permissions;

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserAccount() {
        return userAccount == null ? null : userAccount.trim();
    }

    public void setUserAccount(String userAccount) {
        this.userAccount = userAccount == null ? null : userAccount.trim();
    }

    public String getUserName() {
        return userName == null ? null : userName.trim();
    }

    public void setUserName(String userName) {
        this.userName = userName == null ? null : userName.trim();
    }

    public String getUserPwd() {
        return userPwd == null ? null : userPwd.trim();
    }

    public void setUserPwd(String userPwd) {
        this.userPwd = userPwd == null ? null : userPwd.trim();
    }

    public String getUserPhone() {
        return userPhone == null ? null : userPhone.trim();
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone == null ? null : userPhone.trim();
    }

    public String getUserJob() {
        return userJob == null ? null : userJob.trim();
    }

    public void setUserJob(String userJob) {
        this.userJob = userJob == null ? null : userJob.trim();
    }

    public Integer getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(Integer isDelete) {
        this.isDelete = isDelete;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public Integer getSingleLogin() {
        return singleLogin;
    }

    public void setSingleLogin(Integer singleLogin) {
        this.singleLogin = singleLogin;
    }

    public Integer getUserSys() {
        return userSys;
    }

    public void setUserSys(Integer userSys) {
        this.userSys = userSys;
    }

    public Depart getDepart() {
        if (depart == null) {
            depart = new Depart();
        }
        return depart;
    }

    public void setDepart(Depart depart) {
        this.depart = depart;
    }

    public Company getCompany() {
        if (company == null) {
            company = new Company();
        }
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public List<Role> getRoles() {
        if (roles == null) {
            roles = new ArrayList<>();
        }
        return roles;
    }

    public Role getMaxRole() {
        int maxGrade = 0;
        for (Role role : getRoles()) {
            if (role.getRoleGrade() >= maxGrade) {
                maxRole = role;
            }
        }
        return maxRole == null ? new Role() : maxRole;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<Permission> getPermissions() {
        if (permissions == null) {
            permissions = new ArrayList<>();
        }
        return permissions;
    }

    public void setPermissions(List<Permission> permissions) {
        this.permissions = permissions;
    }

    public List<String> getPerms() {
        perms = new ArrayList<>();
        for (Permission permission : getPermissions()) {
            perms.add(permission.getPermissionEnum());
        }
        return perms;
    }

    public String getUserSalt() {
        return userSalt;
    }

    public void setUserSalt(String userSalt) {
        this.userSalt = userSalt;
    }

    @Override
    public String toString() {
        return JsonUtils.ObjectToString(this);
    }

}
